TARGET_SERVER = cook
TARGET_SERVER_UDP = server_udp
TARGET_CLIENT = client
TARGET_CLIENT_UDP = client_udp

OBJ_SERVER = server.o network.o pointlist.o pthread_func.o
OBJ_SERVER_UDP = server_udp.o network.o
OBJ_CLIENT = client.o
OBJ_CLIENT_UDP = client_udp.o network.o

CLEAN_ALL = *.o *.i *~ *.bak $(TARGET_SERVER) $(TARGET_SERVER_UDP) $(TARGET_CLIENT) $(TARGET_CLIENT_UDP)
CLEAN_NOTARGET = *.o *.i *~ *.bak

CC = gcc
WFG = -Wall
CFG = -c
GFG = -g
OFG = -o
LIBFG = -lpthread

SOURCE_FIRST = $<
SOURCE_ALL = $^
DEST = $@

$(TARGET_SERVER) : $(OBJ_SERVER)
	@echo ------------------------------------------------------------------
	$(CC) $(WFG) $(SOURCE_ALL) $(OFG) $(DEST) $(LIBFG)
	@rm -rf $(CLEAN_NOTARGET)

$(TARGET_SERVER_UDP) : $(OBJ_SERVER_UDP)
	$(CC) $(WFG) $(SOURCE_ALL) $(OFG) $(DEST) $(LIBFG)
	@rm -rf $(CLEAN_NOTARGET)

$(TARGET_CLIENT) : $(OBJ_CLIENT)
	$(CC) $(WFG) $(SOURCE_ALL) $(OFG) $(DEST) $(LIBFG)
	@rm -rf $(CLEAN_NOTARGET)

$(TARGET_CLIENT_UDP) : $(OBJ_CLIENT_UDP)
	$(CC) $(WFG) $(SOURCE_ALL) $(OFG) $(DEST) $(LIBFG)
	@rm -rf $(CLEAN_NOTARGET)

rs : $(TARGET_SERVER)
	@./$(SOURCE_FIRST)

rsu : $(TARGET_SERVER_UDP)
	@./$(SOURCE_FIRST)

rc : $(TARGET_CLIENT)
	@./$(SOURCE_FIRST)

rcu : $(TARGET_CLIENT_UDP)
	@./$(SOURCE_FIRST)

clean :
	rm -rf $(CLEAN_ALL)

%.o : %.c
	@echo ------------------------------------------------------------------
	$(CC) $(WFG) $(CFG) $(SOURCE_FIRST) $(OFG) $(DEST)
